﻿using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using ZhCun.WebCommon;
using MyConsume.AL;
using Swashbuckle.AspNetCore.Swagger;

namespace MyConsume.Web
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.InitServiceConfig(swagerOption =>
            {
                swagerOption.SwaggerDoc("v1", new Info
                {
                    Title = "接口文档 - Test",
                    Version = "v1",
                    Description = "Test",
                    TermsOfService = "None"
                });
                swagerOption.SwaggerDoc("v2", new Info
                {
                    Title = "接口文档 - User",
                    Version = "v2",
                    Description = "User",
                    TermsOfService = "None"
                });
                swagerOption.SwaggerDoc("v3", new Info
                {
                    Title = "接口文档 - Other",
                    Version = "v3",
                    Description = "Other",
                    TermsOfService = "None"
                });
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            //services.AddSignalR();

            //初始化数据权限配置
            DataRights.InitDataRights();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                //app.UseHsts();
            }
            
            app.InitAppConfig(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Test API");
                c.SwaggerEndpoint("/swagger/v2/swagger.json", "用户 API");
                c.SwaggerEndpoint("/swagger/v3/swagger.json", "业务 API");
            });

            app.UseStaticFiles();
            //app.UseCookiePolicy();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            //app.UseSignalR(routes => routes.MapHub<MyHub>("/myHub"));
        }
    }
}